import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import vueJsx from '@vitejs/plugin-vue-jsx'
import {
  externalDeps,
  globalVarMap,
  cssOptimization
} from './build.config'

// UMD构建不支持preserveModules
export default defineConfig({
  plugins: [
    vue(),
    vueJsx()
  ],
  css: cssOptimization,
  build: {
    lib: {
      entry: resolve(__dirname, 'src/index.ts'),
      name: 'EpmsElement',
      fileName: 'umd/index',
      formats: ['umd'] // 只使用UMD格式
    },
    rollupOptions: {
      external: externalDeps,
      output: {
        format: 'umd',
        globals: globalVarMap,
        inlineDynamicImports: true // 启用内联动态导入
      }
    },
    cssCodeSplit: false,
    sourcemap: true,
    minify: 'terser',
    terserOptions: {
      compress: {
        drop_console: false,
        drop_debugger: true
      }
    }
  },
  resolve: {
    alias: {
      '@': resolve(__dirname, './src')
    }
  }
}) 